<template>
  <div>
    <to-search></to-search>
    <div class="con">
      <ul class="left">
        <li
          v-for="(item,index) in navArr"
          :class="index==n?'active':''"
          :key="item.id"
          @click="clickleft(index)"
        >{{item.catename}}</li>
      </ul>

      <ul class="right">
        <li class="item" ref="item" v-for="item in navArr" :key="item.id">
          <h2 class="h2">{{item.catename}}</h2>
          <div class="content">
            <!-- 6.跳转到商品列表 -->
            <div
              class="i"
              v-for="i in item.children"
              :key="i.id"
              @click="$router.push('/list?id='+i.id+'&type=2')"
            >
              <img class="img" :src="$pre + i.img" alt />
              <div class="text">{{ i.catename }}</div>
            </div>
            <van-empty v-if="!item.children" description="暂无数据" />
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { reqcate } from "../../http/http";
export default {
  data() {
    return {
      navArr: [],
      n: 0
    };
  },
  mounted() {
    reqcate().then(res => {
      this.navArr = res.data.list;
    });
  },
  methods: {
    clickleft(index) {
      this.n = index;
      this.$refs.item[this.n].scrollIntoView({
        behavior: "smooth"
      });
    }
  }
};
</script>

<style scoped>
.con {
  height: calc(100vh - 12vw - 1.6rem);
  display: flex;
}
.left {
  width: 30vw;
  height: calc(100vh - 12vw - 1.6rem);
  background-color: #efefef;
}
.left li {
  width: 100%;
  height: 15vw;
  font-size: 5vw;
  text-align: center;
  line-height: 15vw;
  color: #666;
}
.left .active {
  background-color: #fff;
  color: #ff4400;
}

.right {
  flex: 1;
  height: 100%;
  margin-bottom: 2rem;
  overflow-y: auto;
}
.right .item {
  margin: 10px;
  background: #fff;
}

.h2 {
  font-size: 6vw;
  font-weight: bold;
  line-height: 0.6rem;
}
.content {
  overflow: hidden;
}

.i {
  float: left;
  width: 33.33%;
  text-align: center;
}
.img {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 50%;
}
.text {
  font-size: 4vw;
}
</style>